package com.aseo.business.hibernate;

import java.util.List;
import java.util.Set;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;

import org.springframework.stereotype.Service;

import com.aseo.exception.ConstraintViolationException;
import com.aseo.model.dao.Dao;
import com.aseo.model.entity.hibernate.Nota;

@Service(value="com.aseo.business.hibernate.NotaManager")
public class NotaManager {

	@Resource  
	private Dao dao;
	
	public void persist(Nota nota) {
		dao.persist(nota);
	}
	  
	public List<Nota> getAll() {  
		final List<Nota> list = dao.find(Nota.class);  
	    return list;
	}

	public Nota get(Long idNota) {
		return dao.get(Nota.class, idNota);
	}
	
	public void validate(Nota nota) throws ConstraintViolationException {

		Set<ConstraintViolation<Nota>> constraintViolations = dao.validate(nota);
		
		for (ConstraintViolation<Nota> constraintViolation : constraintViolations) {
			throw new ConstraintViolationException(constraintViolation.getMessage());
		}
	}

}